package com.collectplus.express.order;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.collectplus.express.BaseActivity2;
import com.collectplus.express.BaseFragment;
import com.collectplus.express.R;
import com.collectplus.express.logic.AppTab;
import com.shouhuobao.bhi.receiver.ReceiverHistoryFragment;
import com.shouhuobao.bhi.receiver.ReceiverNewFragment;

import droid.frame.view.ViewPagerExt;

/**
 * 项目中用到的appTab
 *
 * @author coffee<br>
 *         2015-6-17下午5:16:53
 */
public class AppTabFragmentActivity extends BaseActivity2 {

    protected ViewPagerExt mViewPager;
    protected TextView[] mTags;
    private ImageView mImgLine;
    protected BaseFragment mFragment1, mFragment2;

    private AppTab appTab;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    protected void findViewById() {
        setContentView(R.layout.receiver_add_main);
        super.findViewById();
        findViewById(R.id.app_bottom_line).setVisibility(View.GONE);
        //
        mTags = new TextView[2];
        mTags[0] = (TextView) findViewById(R.id.add_address_tag_1);
        mTags[1] = (TextView) findViewById(R.id.add_address_tag_2);
        mImgLine = (ImageView) findViewById(R.id.add_address_line_img);
        mViewPager = (ViewPagerExt) findViewById(R.id.viewpager);
        initFragment(); // 先初始化fragment、需要在mViewPager初始化之后调用
        mViewPager.setFragmentItems(getSupportFragmentManager(), mFragment1, mFragment2);
        mViewPager.setSupportScroll(true);

        appTab = new AppTab(getContext());
        appTab.initPosition(mViewPager, mImgLine, mTags);

    }

    protected void initFragment() {
        String title = getIntent().getStringExtra("title");
        if ("添加包裹".equals(title)) {
            mFragment1 = new ReceiverNewFragment();
            mFragment2 = new ReceiverHistoryFragment();
            mTags[0].setText("新建");
            mTags[1].setText("最近添加");
            getAppTitle().setCommonTitle(title);
        } else {

        }
    }

    protected void selectTab(int position) {
        appTab.selectTab(position);
    }
}
